<?php

use app\common\model\Plugin;
use app\common\service\PlatFormFactory;
use think\migration\Seeder;

class AddPlugin extends Seeder
{
    /**
     * Run Method.
     *
     * Write your database seeder using this method.
     *
     * More information on writing seeders is available here:
     * http://docs.phinx.org/en/latest/seeding.html
     */
    public function run()
    {
        $map = [
            [
                'code'         => PlatFormFactory::WECHAT,
                'name'         => '微信支付',
                'desc'         => '微信小程序',
                'scene'        => 4,
                'config'       => [
                    [
                        "name"  => "appid",
                        "label" => "APPID",
                        "type"  => "text",
                        "value" => "",
                    ],
                    [
                        "name"  => "secret",
                        "label" => "Secret",
                        "type"  => "text",
                        "value" => "",
                    ],
                    [
                        "name"  => "mchid",
                        "label" => "商户号",
                        "type"  => "text",
                        "value" => "",
                    ],
                    [
                        "name"  => "key",
                        "label" => "支付密钥（V2）",
                        "type"  => "text",
                        "value" => "",
                    ]
                ],
                'config_value' => [
                    'appid'  => 'wx048ccfebbe3aa21e',
                    'secret' => '115ba7ddd28635ac8f1f1ec4a1005f38',
                    'mchid'  => '1631042255',
                    'key'    => '9bdaa35c0e6a49eec0f345595ac26eb2',
                ],
            ],
            [
                'code'         => PlatFormFactory::BYTE,
                'name'         => '微信支付',
                'desc'         => '抖音小程序',
                'scene'        => 5,
                'config'       => [
                    [
                        "name"  => "appid",
                        "label" => "APPID",
                        "type"  => "text",
                        "value" => "",
                    ],
                    [
                        "name"  => "secret",
                        "label" => "Secret",
                        "type"  => "text",
                        "value" => "",
                    ],
                    [
                        "name"  => "salt",
                        "label" => "支付SALT",
                        "type"  => "text",
                        "value" => "",
                    ],
                    [
                        "name"  => "token",
                        "label" => "验签TOKEN",
                        "type"  => "text",
                        "value" => "",
                    ]
                ],
                'config_value' => [
                    'appid'  => 'tt5fc42979c0f8aadb01',
                    'secret' => '5a0010025fdbaf82812633c3fc79d35fb4e46aea',
                    'salt'   => 'aqsWgVWnTYHOSnnw4QRhmseExwReagC02K79wqsg',
                    'token'  => '!@#$01921473054244864',
                ],
            ],
            [
                'code'         => PlatFormFactory::OFFICIAL,
                'name'         => '微信支付',
                'desc'         => '微信公众号',
                'scene'        => 6,
                'config'       => [
                    [
                        "name"  => "appid",
                        "label" => "APPID",
                        "type"  => "text",
                        "value" => "",
                    ],
                    [
                        "name"  => "secret",
                        "label" => "Secret",
                        "type"  => "text",
                        "value" => "",
                    ],
                ],
                'config_value' => [
                    'appid'  => 'wxebd8975d907c1f2a',
                    'secret' => 'e99ef4a3454309ed3d568bd7342ad30c',
                ],
            ],
            [
                'code'         => 'money',
                'name'         => '粮票支付',
                'desc'         => '粮票支付',
                'scene'        => 0,
                'config'       => [

                ],
                'config_value' => [

                ],
            ],
            [
                'code'         => 'mcbt',
                'name'         => '牧场补贴支付',
                'desc'         => '牧场补贴支付',
                'scene'        => 0,
                'config'       => [

                ],
                'config_value' => [

                ],
            ]
        ];

        foreach ($map as $item) {
            $plugin = Plugin::where('code', $item['code'])->find();

            if (!$plugin) {
                //                dd(serialize($item['config']));
                Plugin::create([
                    'code'         => $item['code'],
                    'name'         => $item['name'],
                    'desc'         => $item['desc'],
                    'config'       => $item['config'],
                    'config_value' => $item['config_value'],
                    'status'       => 1,
                    'type'         => 'payment',
                    'scene'        => $item['scene'],
                ]);
            }
        }
    }
}